package com.sky.controller.user;

import com.sky.pojo.Merchant;
import com.sky.result.Result;
import com.sky.service.UserService.MerchantService;
import com.sky.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author L9629
 */
@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "店铺相关接口")
public class ShoppController {

    public static final String KEY="SHOP_STATUS";

    @Autowired
    RedisTemplate redisTemplate;
    @Resource
    MerchantService userShoppingCart;

    @GetMapping("status")
    @ApiOperation("获取店铺营业状态")
    public Result getShopStatys(){
        Integer key = (Integer) redisTemplate.opsForValue().get(KEY);
        if(Objects.isNull(key)){
            key=0;
        }
        return Result.success(key);
    }
    //  获取店铺电话
    @GetMapping("/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result   getMerchantInfo(){
        //  获取唯一商家对象信息
        Merchant merchant = userShoppingCart.findShopById(1L);
        String  shopName = merchant.getShopName();
        String  shopAddress = merchant.getShopAddress();
        String  shopTelephone = merchant.getShopTelephone();
        ShopVO build = ShopVO.builder().phone(shopTelephone).shopName(shopName).shopAddress(shopAddress).build();
        return Result.success(build);
    }


}
